﻿using System;
using System.Collections.Generic;
using System.Text;
using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Sms.V20190711;
using TencentCloud.Sms.V20190711.Models;
using Infrastructure.Error;

namespace OtherLib.TenXun
{
    public static class SendSmsUtil
    {

        
        public static bool SendSms(string phone, string code)
        {
            ClientProfile clientProfile = new ClientProfile();
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.Endpoint = ("sms.tencentcloudapi.com");
            clientProfile.HttpProfile = httpProfile;

            SmsClient client = new SmsClient(TenXunConfig.Cred, "", clientProfile);
            SendSmsRequest req = new SendSmsRequest();
            req.PhoneNumberSet = new string[] { "86" + phone };
            req.TemplateID = "744053";
            req.Sign = "够莱富";
            req.TemplateParamSet = new string[] { code };
            req.SmsSdkAppid = "1400432878";

            SendSmsResponse resp = client.SendSmsSync(req);

            if (resp.SendStatusSet[0].Code == "Ok")
            {
                return true;
            }
            else
            {
                throw new BizException((string)resp.SendStatusSet[0].Message);
            }
        }
    }
}
